package xiaohong.data.tree.order;

import xiaohong.data.tree.binary.TreeNode;

import java.util.List;

public class ArrayBinaryTree {

    private List<TreeNode> list;

    public ArrayBinaryTree(List<TreeNode> list) {
        this.list = list;
    }

    public void firstPrint() {
        firstPrint(0);
    }

    public void middlePrint() {
        middlePrint(0);
    }

    public void lastPrint() {
        lastPrint(0);
    }


    private void firstPrint(int level) {
        if (list.isEmpty()) {
            return;
        }
        System.out.println(list.get(level));
        if (2 * level + 1< list.size()) {
            firstPrint(2 * level + 1);
        }
        if (2 * level + 2< list.size()) {
            firstPrint(2 * level + 2);
        }
    }

    private void middlePrint(int level) {
        if (list.isEmpty()) {
            return;
        }
        if (2 * level + 1< list.size()) {
            firstPrint(2 * level + 1);
        }
        System.out.println(list.get(level));
        if (2 * level + 2< list.size()) {
            firstPrint(2 * level + 2);
        }
    }

    private void lastPrint(int level) {
        if (list.isEmpty()) {
            return;
        }
        if (2 * level + 1< list.size()) {
            firstPrint(2 * level + 1);
        }
        if (2 * level + 2< list.size()) {
            firstPrint(2 * level + 2);
        }
        System.out.println(list.get(level));
    }








}
